﻿using AutoTest.Business.Dto.AdminUser;
using AutoTest.Business.Dto.UserInfo;
using AutoTest.Business.IServices;
using AutoTest.Business.Vo.AdminUser;
using AutoTest.Business.Vo.UserInfo;
using AutoTest.Framework.Api;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AutoTest.WebApi.Controllers
{
    /// <summary>
    /// 用户
    /// </summary>
    [Route("api/user")]
    public class UserController : Controller
    {
        private readonly IUserService _userService;

        /// <summary>
        /// 构造函数
        /// </summary>
        public UserController(IUserService userService)
        {
            _userService = userService;
        }
        /// <summary>
        /// 授权回调提交接口
        /// </summary>
        /// <param name="loginDto">用户登录信息</param>
        /// <returns></returns>
        [HttpPost("login")]
        [AllowAnonymous]
        public async Task<ApiResult<LoginUserVo>> Login([FromBody] UserLoginDto loginDto)
        {
            return await ApiResult<LoginUserVo>.Successed(() => _userService.UserLoginAsync(loginDto));
        }

        /// <summary>
        /// 查询当前用户开通的产品
        /// </summary>
        /// <returns></returns>
        [HttpPost("current-user/product")]
        public async Task<ApiResult<UserProductVo>> GetCurrentUserProductsAsync()
        {
            return await ApiResult<UserProductVo>.Successed(() => _userService.GetCurrentUserProductsAsync());
        }

        /// <summary>
        /// 授权回调提交接口
        /// </summary>
        /// <param name="checkDto">用户登录信息</param>
        /// <returns></returns>
        [HttpPost("check/product")]
        public async Task<ApiResult> CheckUserProductAsync([FromBody] UserProductCheckDto checkDto)
        {
            return await ApiResult.FromResult(() => _userService.CheckUserProductAsync(checkDto.FrontPath));
        }
    }
}
